#!/usr/bin/perl
# 
#  Exercise 6.4 
# 
# Write a subroutine to look for command-line arguments such as -help, -h, and --
# help. Recall that command-line arguments appear in the @ARGV array. Call your 
# subroutine from a main program. If you give the program any of the named com-
# mand-line arguments, when you pass them into the subroutine it should return a 
# true value. If this is the case, have the program print out a help message in a 
# $USAGE variable and exit.
#
# Answer to Exercise 6.4

use strict;
use warnings;

my $USAGE = "USAGE: exer06.04 [ -help | -h | --help ]\n";

if( there_is_a_request_for_help(@ARGV) ) {

	print $USAGE;
	exit;
}

exit;

sub there_is_a_request_for_help {

	my(@arguments) = @_;

	# You could use the "grep" function like this:
	# if( grep( /^(-help|-h|--help)$/, @arguments) ) { return 1; }
	# But we won't see "grep" until Chapter 11.  So we'll do
	# it by looping through all the arguments:

	for(@arguments) {
		if( /^(-help|-h|--help)$/ ) {
			return 1;
		}
	}

	# At this point, you know there's no request for help,
	# so you return "false"

	return 0;
}
